package com.neo.impatient.C14_PatternMatchingAndCaseClasses.C14_01_match

object MatchTest {



  def testMatch = {
    var ch1: String = ""
    val ch: String  = "aa"
    ch match{
      case "aa" => println(ch + "aa")
      case "bb" => print(ch)
      case  ch => ch1 =  "ch" + ch
    }

    print(ch1 + "test")

  }


  def testmach1 = {


    val bools = Seq(true, false)

    for (bool <- bools) {
      bool match {
        case true => println("Got heads")
        case false => println("Got tails")
      }
    }
  }

  def testMatch2 = {
    for {
      x <- Seq(1, 2, 2.7, "one", "two", 'four) // ➊
    } {
      val str = x match { // ➋
        case 1 => "int 1" // ➌
        case i: Int => "other int: "+i // ➍
        case d: Double => "a double: "+x // ➎
        case "one" => "string one" // ➏
        case s: String => "other string: "+s // ➐
        case unexpected => "unexpected value: " + unexpected // ➑
      }
      println(str) // ➒
    }
  }


  def testMatch3 = {
    for {
      x <- Seq(1, 2, 2.7, "one", "two", 'four)
    } {
      val str = x match {
        case 1 => "int 1"
        case _: Int => "other int: "+x
        case _: Double => "a double: "+x
        case "one" => "string one"
        case _: String => "other string: "+x
        case _ => "unexpected value: " + x
      }
      println(str)
    }



  }



  def main(args: Array[String]): Unit = {

    val ch: String  = "aa"
    ch match{
      case "aa" => println(ch + "aa1")
      case "bb" => print(ch)
    }


    //testMatch
    println("testmach1")
    //testmach1
    //testMatch2

    testMatch3



  }




}
